package tests;

import static org.junit.Assert.*;

import org.junit.Test;

import communicationMessages.AddPostMessage;
import communicationMessages.Message;


public class MsgTestAll {
	
	String userName,subject,body,subForumId,threadMsgId,responseToMsgId,strIsThread;
	String delimiter = Message.delimiter;
	
	@Test
	public void testRegularAddPost()
	{
		initFileds();
		Message msg = new AddPostMessage();
		String content = userName + delimiter  + subForumId + delimiter + threadMsgId + delimiter + responseToMsgId
			 + delimiter + subject + delimiter + body + delimiter + strIsThread + delimiter;
		msg.setContent(content);
		assertEquals(msg.getAnswer(),"addPostMessage"+delimiter+"success"+delimiter);
	}
	
	@Test
	public void testWrongParameterAddPost()
	{
		initFileds();
		Message msg = new AddPostMessage();
		String content = userName + delimiter;
		msg.setContent(content);
		assertEquals(msg.getAnswer(),"addPostMessage"+delimiter+"success"+delimiter);
	}
	
	@Test
	public void testWrongSubForumIdAddPost()
	{
		initFileds();
		Message msg = new AddPostMessage();
		String content = userName + delimiter  + "999" + delimiter + threadMsgId + delimiter + responseToMsgId
			 + delimiter + subject + delimiter + body + delimiter + strIsThread + delimiter;
		msg.setContent(content);
		assertEquals(msg.getAnswer(),"pathNotFound" + delimiter);
	}
	
	@Test
	public void testWrongMsgFormatAddPost()
	{
		initFileds();
		Message msg = new AddPostMessage();
		String content = userName + delimiter  + subForumId + delimiter + threadMsgId + delimiter + responseToMsgId
			 + delimiter + "" + delimiter + "" + delimiter + strIsThread + delimiter;
		msg.setContent(content);
		assertEquals(msg.getAnswer(),"failed"+delimiter+"add tpost Msg wrong format"+delimiter);
	}

	private void initFileds() {
		userName = "admin";
		subject = "subject";
		body = "body";
		subForumId = "1";
		threadMsgId = "2";
		responseToMsgId = "2";
		strIsThread = "true";
	}

}
